#include "options.h"
extern QSqlDatabase db;
extern QString get_setting(QString);
extern void set_setting(QString,QString);
options::options( QWidget *parent) :
    QDialog(parent)
{





ui.setupUi(this);
connect(ui.pushButton,SIGNAL(clicked()),this,SLOT(save()));




QString fnt=get_setting("font");
if (fnt.isEmpty())fnt="Nokia Sans,18,-1,5,50,0,0,0,0,0";
int size=get_setting("font_size").toLong();
if (size==0)size=10;

QString filter=get_setting("filter");
if (filter.isEmpty())filter="*.mp3 *.flack *.ogg";


ui.comboBox->setCurrentIndex(get_setting("rotate").toLong());
QFont h(fnt);

ui.fontComboBox->setCurrentFont(h);
ui.spinBox->setValue(size);

size=get_setting("volume_change").toLong();
if (size==0)size=10;
ui.spinBox_2->setValue(size);

ui.lineEdit->setText(filter);
ui.lineEdit_2->setText(get_setting("last_login"));
ui.lineEdit_3->setText(get_setting("last_password"));
ui.comboBox_2->setCurrentIndex(get_setting("internet_load").toLong());
ui.comboBox_3->setCurrentIndex(get_setting("head_disconnect").toLong());
ui.comboBox_4->setCurrentIndex(get_setting("head_connect").toLong());
ui.comboBox_5->setCurrentIndex(get_setting("start_action").toLong());
ui.comboBox_6->setCurrentIndex(get_setting("volume_behaviour").toLong());


}

void options::save(){
   set_setting("rotate",QString("%1").arg(ui.comboBox->currentIndex()));
   set_setting("font",ui.fontComboBox->currentFont().toString());
   set_setting("font_size",QString("%1").arg(ui.spinBox->value()));
   set_setting("filter",ui.lineEdit->text());
   set_setting("last_login",ui.lineEdit_2->text());
   set_setting("last_password",ui.lineEdit_3->text());
   set_setting("internet_load",QString("%1").arg(ui.comboBox_2->currentIndex()));
   set_setting("head_disconnect",QString("%1").arg(ui.comboBox_3->currentIndex()));
   set_setting("head_connect",QString("%1").arg(ui.comboBox_4->currentIndex()));
   set_setting("start_action",QString("%1").arg(ui.comboBox_5->currentIndex()));
   set_setting("volume_behaviour",QString("%1").arg(ui.comboBox_6->currentIndex()));
   set_setting("volume_change",QString("%1").arg(ui.spinBox_2->value()));
   this->accept();
   this->close();
}
